package com.max.cms0.web.contorller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.max.cms0.entity.Slideshow;
import com.max.cms0.exception.ServiceException;
import com.max.cms0.result.Result;
import com.max.cms0.result.ResultCode;
import com.max.cms0.service.SlideshowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: cms0
 * @BelongsPackage: com.max.cms0.web.contorller
 * @Author: MHN
 * @CreateTime: 2024-11-18  14:44
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("slideshow")
public class SlideshowController {
    @Autowired
    SlideshowService slideshowService;

    @ApiOperation("根据id查询轮播图信息")
    @GetMapping("queryById/{id}")
    public Result findById(@PathVariable Integer id){
        Slideshow slideshow = slideshowService.getById(id);
        return Result.success(slideshow);
    }

    @ApiOperation("查询所有轮播图信息")
    @GetMapping("queryAllEnable")
    public Result findAll(){
        List<Slideshow> slideshows = slideshowService.queryAllEnable();
        return Result.success(slideshows);
    }

    @ApiOperation("增加或更新轮播图")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Slideshow slideshow){
        slideshowService.saveOrUpdate(slideshow);
        return Result.success("操作成功");
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        slideshowService.removeById(id);
        return Result.success("删除成功");
    }

    @ApiOperation("根据ids删除")
    @DeleteMapping("deleteByBatch/{ids}")
    public Result deleteByBatch(@PathVariable List<Integer> ids){
        slideshowService.removeByIds(ids);
        return Result.success("删除成功");
    }
}
